import java.util.Stack;



/**
 * @package: BrickCAD
 * @className: CommandProcessor.java
 * @package: default
 * @author: Sean , Jack, Lester, Erik Telstad
 * @date_created: November 16, 2009
 * @last_motified: November 16, 2009
 * 
 * 
 * 
 */

public class CommandProcessor{
	private Command acmd;
	private Stack<Command> undo;
	private Stack<Command> redo;
	
	public CommandProcessor() {
		undo = new Stack<Command>();
		redo = new Stack<Command>();
		acmd = null;
		
	}
	
	public void execute(Command cmd){
		acmd = cmd;
		acmd.execute();
		undo.push(acmd);
		redo.clear();
		
	}
	
	public void undo(){
		if(!undo.empty()){
			acmd = undo.pop();
			acmd.undo();
			redo.push(acmd);
		}
//		else
//			System.out.println("undo stack is empty");
	}
	
	public void redo(){
		if(!redo.empty()){
			acmd = redo.pop();
			acmd.execute();
			undo.push(acmd);
		}
//		else
//			System.out.println("redo stack is empty");
	}

}
